The width of a sprite asset, in pixels — the same size the editor’s art already has for spr itself, whether or not any instance is currently showing it.
sprite_width(spr) -> int| Name | Type |
|---|---|
spr | sprite |
int
The width of a sprite asset, in pixels - the same size the editor's art already has for spr itself, whether or not any instance is currently showing it. Useful for laying something out against a sprite's own size instead of a hard-coded number that would go stale the moment the art changes.
x = room_right() - sprite_width(spr_doc_hero) / 2;Puts this instance against the room's right edge, with its picture touching the edge instead of poking out past it. The room's x counts from its top-left corner, so room_right() is the right edge. The instance's origin is the middle of its picture (unless you set another), so it has to sit half a sprite's width in from that edge. The position stays correct even if the room's size or the sprite's own art ever changes.
A pure, compile-time read of the asset’s own shape (the asset tool already knows every sprite’s width before the ROM boots) — call it with a literal sprite name (sprite_width(spr_player)) and it folds to a constant at -O2, no runtime cost at all; call it with a sprite-typed variable whose value can change at runtime and it still costs only a pointer dereference, never a search.